define(['app'], function(app) {
	'use strict';

	//实例化方法
	var factory = function(Http) {

		function get_data_productmanager_publish_brand(result) {
			if(HTTP_ISLOGIC) {
				result = '{"success": true,"msg": "","result": {"brand": [' +
					'{"id": "001","name": "世达"},' +
					'{"id": "002","name": "博士"}' +
					']},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else {
				return result;
			}
		}

		function get_data_productmanager_publish_fare(result) {
			if(HTTP_ISLOGIC) {
				result = '{"success": true,"msg": "","result": {"dlytype": [' +
					'{ "id": "001","name": "运费模板001"},' +
					'{ "id": "002", "name": "运费模板002"}' +
					']},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else {
				return result;
			}
		}

		function get_data_productmanager_publish_property(result) {
			if(HTTP_ISLOGIC) {
				result = '{"success": true,"msg": "","result": {"property":[' +
					'{"id":"001","name":"颜色"},' +
					'{"id":"002","name":"重量"}' +
					']},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else {
				return result;
			}
		}

		function get_data_specification(result) {
			if(HTTP_ISLOGIC) {
				result = '{"success": true,"msg": "","result": { "specification": [' +
					'{"type_id": "001","type_name": "尺寸","value": [' +
					'{"id": "001","name": "长度"},' +
					'{"id": "002","name": "宽度"},' +
					'{"id": "003","name": "高度"},' +
					'{"id": "004","name": "形状"}]},' +
					'{"type_id": "002","type_name": "颜色","value": [' +
					'{"id": "005","name": "上表面"},' +
					'{"id": "006","name": "下表面"}]},' +
					'{"type_id": "003","type_name": "其他","value": [' +
					'{"id": "007","name": "重量"}]}' +
					']},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else {
				return result;
			}
		}

		function get_data_productmanager_publish_edit(result) {
			if(HTTP_ISLOGIC) {
				result = '{"success": true,"msg": "","result": { "goods_id": "001"},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else {
				return result;
			}
		}

		function get_cat_list(result) {
			if(HTTP_ISLOGIC) {
				result = '{"success":true,"msg":"","result":{"custom_cat":[{"custom_cat_id":1,"store_id":1,"parent_id":1,"is_leaf":false,"cat_name":"大分类","disabled":false,"p_order":1,"goods_count":10,"child_count":2},{"custom_cat_id":2,"store_id":2,"parent_id":1,"is_leaf":true,"cat_name":"中分类","disabled":false,"p_order":2,"goods_count":10,"child_count":1}]},"session":"7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else {
				return result;
			}
		}
		
		//配件
//		function get_suitgoods_list(result) {
//			if(HTTP_ISLOGIC) {
//				result = '{"success":true,"msg":"","result":{"goods":[{"id":"001","name":"螺丝刀","bn":"P58983D5B7FD174002","suit_price":"152.00","price":"100.00","store":25,"image":{"id":"001","image":""}},{"id":"002","name":"螺丝","bn":"P585A2FF85E4EA5750","suit_price":"152.00","price":"100.00","store":25,"image":{"id":"002","image":""}}]},"session":"7311da98bd0f18eb15a96bcb263f4153"}';
//				return JSON.parse(result);
//			} else {
//				return result;
//			}
//		}
		
		//返回信息
		return {
			//商品品牌
			productmanager_publish_brand: function(callback) {
				Http.post({
						method: 'goods.brand.getlist',
					},
					function(result) {
						//请求成功
						if(callback)
							callback(get_data_productmanager_publish_brand(result).result);
					},
					function(e) {
						//请求异常
					},
					function() {
						//请求完成，一般不做什么事情
					});
			},
			//商品运费模板
			productmanager_publish_fare: function(callback) {
				Http.post({
						method: 'goods.brand.getlist',
					},
					function(result) {
						//请求成功
						if(callback)
							callback(get_data_productmanager_publish_fare(result).result);
					},
					function(e) {
						//请求异常
					},
					function() {
						//请求完成，一般不做什么事情
					});
			},
			//商品属性
			productmanager_publish_property: function(custom_cat_id, callback) {
				Http.post({
						method: 'goods.property.getlist',
						custom_cat_id: custom_cat_id,
					},
					function(result) {
						//请求成功
						if(callback)
							callback(get_data_productmanager_publish_property(result).result);
					},
					function(e) {
						//请求异常
					},
					function() {
						//请求完成，一般不做什么事情
					});
			},
			//商品规格
			specification: function(custom_cat_id, callback) {
				Http.post({
						method: 'goods.specification.getlist',
						custom_cat_id: custom_cat_id,
						pagelimit: 5,
						nPage: 1,
						show_count: 10,
					},
					function(result) {
						//请求成功
						if(callback)
							callback(get_data_specification(result).result);
					},
					function(e) {
						//请求异常
					},
					function() {
						//请求完成，一般不做什么事情
					});
			},

			//商品编辑
			productmanager_publish_edit: function(goods_id, goods_state, cat_id, name, property, bn, keywords, brief, image, brand_id, specification, dlytype_id, is_freepost, is_marketable, is_salewithoutstore, cat_list_id, related_goods, meta_keyword, meta_describe, suitgoods_id, callback) {
				Http.post({
					method: 'goods.goods.edit',
					updateParams: {
						goods_id: goods_id,
						goods_state: goods_state,
						cat_id: cat_id,
						name: name,
						property: property,
						bn: bn,
						keywords: keywords,
						brief: brief,
						image: image,
						brand_id: brand_id,
						specification: specification,
						dlytype_id: dlytype_id,
						is_freepost: is_freepost,
						is_marketable: is_marketable,
						is_salewithoutstore: is_salewithoutstore,
						cat_list_id: cat_list_id,
						related_goods: related_goods,
						meta_keyword: meta_keyword,
						meta_describe: meta_describe,
						suitgoods_id: suitgoods_id
					}
				},
				function(result) {
					//请求成功
					if(callback)
						callback(get_data_productmanager_publish_edit(result).result);
				},
				function(e) {
					//请求异常
				},
				function() {
					//请求完成，一般不做什么事情
				});
			},
			//商品自定义分类
			get_cat_list: function(callback) {
				Http.post({
					method: 'goods.cat.list.get'
				},function(result) {
					//请求成功
					if(callback)
						callback(get_cat_list(result).result);
				},function(e) {
					//请求异常
				},function() {
					//请求完成，一般不做什么事情
				});
			},
			//配件商品
//			get_suitgoods_list: function(callback) {
//				Http.post({
//					method: 'goods.suitgoods.getlist'
//				},function(result) {
//					//请求成功
//					if(callback)
//						callback(get_suitgoods_list(result).result);
//				},function(e) {
//					//请求异常
//				},function() {
//					//请求完成，一般不做什么事情
//				});
//			}
			
		};
	}

	factory.$inject = ['Http'];
	return app.registerService("Productmanager_publish", factory);
});